home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** File: DoEvent.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1990-1993 Apple Computer, Inc.
- ** All rights reserved.
- */
-
- /* You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "DSC Sample Code"
- ** after having made changes. If you're going to re-distribute the source,
- ** we require that you make it clear in the source that the code was
- ** descended from Apple Sample Code, but that you've made changes. */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "App.h" /* Get the application includes/typedefs, etc. */
- #include "App.protos.h" /* Get the prototypes for application. */
-
- #ifndef __CTLHANDLER__
- #include "CtlHandler.h"
- #endif
-
- #ifndef __DESK__
- #include <Desk.h>
- #endif
-
- #ifndef __DISKINIT__
- #include <DiskInit.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __TEXTEDITCONTROL__
- #include "TextEditControl.h"
- #endif
-
- #ifndef __TEXTSERVICES__
- #include "TextServices.h"
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
-
-
- /*****************************************************************************/
-
-
-
- extern Cursor *gCursorPtr; /* See the file Window.c for comments about this global. */
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* Do the right thing for an event. Determine what kind of event it is, and
- ** call the appropriate routines. */
-
- #pragma segment Main
- void DoEvent(EventRecord *event)
- {
- Point pt;
- OSErr err;
-
- switch(event->what) {
-
- case nullEvent:
- DoIdleTasks(event);
- break;
-
- case mouseDown:
- DoMouseDown(event);
- break;
-
- case autoKey:
- case keyDown: /* Check for menukey equivalents. */
- DoKeyDown(event);
- break;
-
- case activateEvt:
- gCursorPtr = nil; /* Force recalculation of the cursor. */
- DoActivate((WindowPtr)event->message);
- if (TSMTEAvailable()) TSMEvent(event);
- break;
-
- case updateEvt:
- DoUpdate((WindowPtr)event->message);
- break;
-
- case kHighLevelEvent:
- gCursorPtr = nil; /* Force recalculation of the cursor. */
- DoHighLevelEvent(event);
- break;
-
- case osEvt:
- gCursorPtr = nil; /* Force recalculation of the cursor. */
- switch ((event->message >> 24) & 0xFF) {
- /* Must logical and with 0xFF to get only low byte. */
- /* High byte of message. */
-
- case mouseMovedMessage:
- DoIdleTasks(event);
- break;
-
- case suspendResumeMessage:
- /* Suspend/resume is also an activate/deactivate. */
- gInBackground = !((event->message) & resumeFlag);
- CTEConvertClipboard((event->message) & convertClipboardFlag, !gInBackground);
- DoActivate(FrontWindow());
- HiliteWindows();
- break;
- }
- break;
-
- case diskEvt:
- gCursorPtr = nil; /* Force recalculation of the cursor. */
- if (HiWord(event->message) != noErr) {
- SetPt(&pt, kDILeft, kDITop);
- err = DIBadMount(pt, event->message);
- }
- break; /* It is not a bad idea to at least call DIBadMount
- ** in response to a diskEvt, so that the user can
- ** format a floppy. */
- }
-
- DoCursor();
- DoAdjustMenus();
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* •• Called by DTS.Lib..framework. •• */
-
- /* This is called when a window is activated or deactivated. */
-
- #pragma segment Main
- void DoActivate(WindowPtr window)
- {
- RgnHandle rgn, oldClip;
- Point pt;
-
- NotifyCancel();
-
- if (IsAppWindow(window)) {
-
- SetPort(window);
- DoCtlActivate(window);
- DoDrawFrame(window, true); /* Redraw frame for new activate state. */
-
- CopyRgn(((WindowPeek)window)->contRgn, rgn = NewRgn());
- DiffRgn(rgn, ((WindowPeek)window)->updateRgn, rgn);
- /* Don't draw any part that's already destined to draw due to an update event.
- ** This prevents part of an exposed window from drawing twice, and thus avoids
- ** flickering. */
-
- BeginContent(window);
-
- pt.h = pt.v = 0;
- GlobalToLocal(&pt);
- OffsetRgn(rgn, pt.h, pt.v);
- /* This offset may seem wrong, since the origin may not be 0,0. It is actually correct,
- ** since at the time of the GlobalToLocal, the port's origin was set to the content origin.
- ** A clearer way to look at this is in two steps:
- ** 1) With the port's origin at 0,0, do a GlobalToLocal on 0,0, and then offset the new clip
- ** by that amount.
- ** 2) Once the port's origin is set correctly, the new clip needs to be offset again, based
- ** on the origin value. (The clipRgn travels with the origin, unlike the visRgn.)
- ** The above is what automatically happens when you do the GlobalToLocal of 0,0 on the
- ** correct origin. Offsets are additive. One step -- no muss, no fuss. */
-
- GetClip(oldClip = NewRgn());
- SetClip(rgn);
- DoDrawControls(window, true); /* Redraw content scrollbars for new activate state. */
- SetClip(oldClip);
- DisposeRgn(oldClip);
- DisposeRgn(rgn);
-
- EndContent(window);
- }
- }
-
-
-
-